﻿using System;
using System.Linq;
using Missbot.Service;
using MongoDB.Bson.Serialization.Attributes;

namespace Missbot.AIModule.Schedulers.MisskeyUpdateNotice
{
    public class MisskeyUpdateNoticeRec : DbBaseEntity
    {
        public string VersionNo { get; init; }
        
        [BsonDateTimeOptions(Kind = DateTimeKind.Local)]
        public DateTime NoticeTime { get; set; } = DateTime.Now;
    }

    public static class MisskeyUpdateNoticeRecDA
    {
        public static string GetLastVersion()
        {
            return MongoService<MisskeyUpdateNoticeRec>.Get(p => true, p => p.NoticeTime, false, 0, 1).FirstOrDefault()?.VersionNo ?? string.Empty;
        }

        public static void Insert(this MisskeyUpdateNoticeRec entity)
        {
            MongoService<MisskeyUpdateNoticeRec>.Insert(entity);
        }
    }
}